@extends('layout.adminlayout')
@section('css')
<script src="/admin/js/metisMenu.min.js"></script>
<script src="/admin/js/custom.js"></script>
<style>
	th,td {
	  border: 0.1em solid #ccc !important
	}
</style>
@endsection
@section('content')
<div class="tables"> 
	<div class="table-responsive bs-example widget-shadow"> 
		<h4>待审批列表 :</h4> 
		<table class="table table-bordered">
			{{csrf_field()}}
        	<tbody>
			@if(!null==$data)
				@foreach($data as $v) 
         		<tr>
         		<tr><th></th><td></td></tr> 
	         		<tr> 
		          		<th style="text-align: center">待审批编号</th> 
		          		<th scope="row" style="text-align: center">{{$v['id']}}</th> 
	         		</tr> 
	          		<tr> 
			          	<th style="text-align: center">代理商名称</th> 
			          	<td style="text-align: center">{!! $v['agent_name'] !!}</td> 
		         	</tr> 
			        <tr> 
			          	<th style="text-align: center">联系人</th> 
			          	<td style="text-align: center">{{$v['linkman']}}</td> 
			        </tr> 
		          	<tr> 
		          		<th style="text-align: center">手机号</th> 
		          		<td style="text-align: center">{{$v['phone']}}</td> 
		         	</tr> 
		          	<tr> 
		          		<th style="text-align: center">状态</th> 
		          		<td style="text-align: center">
							@if($v['status'] == 0)
								待审批
							@elseif($v['status'] == 1)
								审批通过
							@elseif($v['status'] == 2)
								审批未通过
							@endif</td> 
		         	</tr> 
		         	<tr> 
			          	<th style="text-align: center">操作</th> 
			          	<td style="text-align: center" id="operate_{{$v['id']}}">
							@if($v['status'] == 0)
								<a href="javascript:void (0)" onclick="agree({{$v['id']}})">通过</a>&nbsp;|&nbsp;<a href="javascript:void (0)" onclick="disagree({{$v['id']}})">不通过</a>
							@else
								<span>已完成操作</span>
							@endif</td> 
		         	</tr> 
	         	</tr>
				@endforeach
			@endif
		</table>
	</div>
</div>
<script>
	//同意
    function agree($approveId) {
        $.ajax({
            type:'post',
            url:"/admin/agent/agree",
            async:false,
            data:{
                "_token": $("input[name=_token]").val(),
                'approveId':$approveId
            },
            dataType:'json',
            success:function (data) {
            }
        })
        $('#operate_'+$approveId).empty();
		$('#operate_'+$approveId).append('<span>已完成操作</span>');
    }

    //不同意
	function disagree($approveId){
        $.ajax({
            type:'post',
            url:"/admin/agent/disagree",
            async:false,
            data:{
                "_token": $("input[name=_token]").val(),
                'approveId':$approveId
            },
            dataType:'json',
            success:function (data) {
            }
        })
        $('#operate_'+$approveId).empty();
        $('#operate_'+$approveId).append('<span>已完成操作</span>');
	}
</script>
@endsection

